import { IHomeState,ISlider,IShopList,IGridList,directionName } from '@/typeings/home';
import {IGlobalState} from '../index';
import {Module} from 'vuex'
import * as Types from '../action-types'
import {getSliderList,getGridList,getShopList}from '@/api/home/index'
// 首页
const state:IHomeState ={
	logo:"",
	address:"",
	sliders:[],
	gridConfiguration:{
		columnNum: 5, //列数
		square: false, //是否正方形鸽子
		gutter: 0, //各自间距
		border: false, //是否显示边距
		isCustom: true, // 是否自定义
		direction: directionName[1],
		data:[]
	},
	shopList:{
		hasMore: true,//有没有更多数据
		loading: false,//默认没有正在加载
		offset:0,
		limit:5,
		list:[]// 当前已经显示到页面的课程
	}

}
const mutations={
	[Types.SET_SLIDERLIST](state:IHomeState, paylpad:ISlider[]){
		state.sliders = paylpad
	},
	[Types.SET_GRIDLIST](state:IHomeState, paylpad:IGridList[]){
		state.gridConfiguration.data = paylpad
	},
	[Types.SET_SHOPLIST](state:IHomeState, paylpad:IShopList[]){
		state.shopList.list = paylpad
	},
	[Types.GET_ADDRESS](state:IHomeState, paylpad:string){
		state.address = paylpad
	}
}
const actions={
	async [Types.SET_SLIDERLIST]({commit}:any){
		let sliders = await getSliderList();
		commit(Types.SET_SLIDERLIST,sliders)
	},
	async [Types.SET_GRIDLIST]({commit}:any){
		let gridList = await getGridList()
		commit(Types.SET_GRIDLIST,gridList)
	},
	async [Types.SET_SHOPLIST]({commit}:any){
		let shopList = await getShopList()
		commit(Types.SET_SHOPLIST,shopList)
	}
}
//Module里的参数 1）自状态 2）全局状态
const home:Module<IHomeState,IGlobalState> ={
	namespaced:true,
	state,
	mutations,
	actions
}
export default home;